package com.yanfan.lighting.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.lighting.domain.IbmsLightingLoop;
import com.yanfan.lighting.service.IIbmsLightingLoopService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 照明系统控制回路Controller
 *
 * @author genluo
 * @date 2024-08-27
 */
@Api(tags = "照明系统控制回路")
@RestController
@RequestMapping("/lighting/lightingLoop")
public class IbmsLightingLoopController extends BaseController {
    @Autowired
    private IIbmsLightingLoopService ibmsLightingLoopService;

    /**
     * 查询照明系统控制回路列表
     */
    @ApiOperation("照明系统控制回路分页列表")
    @PreAuthorize("@ss.hasPermi('lighting:lightingLoop:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsLightingLoop ibmsLightingLoop) {
        startPage();
        List<IbmsLightingLoop> list = ibmsLightingLoopService.queryPageList(ibmsLightingLoop);
        return getDataTable(list);
    }

    /**
     * 导出照明系统控制回路列表
     */
    @ApiOperation("导出照明系统控制回路列表")
    @PreAuthorize("@ss.hasPermi('lighting:lightingLoop:export')")
    @Log(title = "照明系统控制回路", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsLightingLoop ibmsLightingLoop) {
        List<IbmsLightingLoop> list = ibmsLightingLoopService.queryPageList(ibmsLightingLoop);
        ExcelUtil<IbmsLightingLoop> util = new ExcelUtil<IbmsLightingLoop>(IbmsLightingLoop.class);
        util.exportExcel(response, list, "照明系统控制回路数据");
    }

    /**
     * 获取照明系统控制回路详细信息
     */
    @ApiOperation("获取照明系统控制回路详细信息")
    @PreAuthorize("@ss.hasPermi('lighting:lightingLoop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ibmsLightingLoopService.getById(id));
    }

    /**
     * 新增照明系统控制回路
     */
    @ApiOperation("新增照明系统控制回路")
    @PreAuthorize("@ss.hasPermi('lighting:lightingLoop:add')")
    @Log(title = "照明系统控制回路", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsLightingLoop ibmsLightingLoop) {
        return toAjax(ibmsLightingLoopService.save(ibmsLightingLoop));
    }

    /**
     * 修改照明系统控制回路
     */
    @ApiOperation("修改照明系统控制回路")
    @PreAuthorize("@ss.hasPermi('lighting:lightingLoop:edit')")
    @Log(title = "照明系统控制回路", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsLightingLoop ibmsLightingLoop) {
        return toAjax(ibmsLightingLoopService.updateById(ibmsLightingLoop));
    }

    /**
     * 删除照明系统控制回路
     */
    @ApiOperation("删除照明系统控制回路")
    @PreAuthorize("@ss.hasPermi('lighting:lightingLoop:remove')")
    @Log(title = "照明系统控制回路", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsLightingLoopService.removeBatchByIds(Arrays.asList(ids)));
    }
}
